﻿Imports System.Data.SqlClient
Imports System.Data

Partial Class _Default
    Inherits System.Web.UI.Page
    Dim cn As New SqlConnection(ConfigurationSettings.AppSettings("conn"))
    Dim catid As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Label2.Text = Session("username")
        Label2.Text = Session("username")
        Try

            Dim str As String = Request.QueryString("id")
            Dim cmd As New SqlCommand("SELECT imageid, imageurl, uploadby, title, (likes) AS popularity FROM imagetable ORDER BY popularity DESC", cn)
            Dim da As New SqlDataAdapter(cmd)
            cn.Open()
            Dim dt As New DataSet
            da.Fill(dt)
            GridView1.DataSource = dt
            GridView1.DataBind()
        Catch
        End Try

    End Sub



    Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
        GridView1.PageIndex = e.NewPageIndex
        GridView1.DataBind()
    End Sub

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
        Dim str As String = GridView1.Rows(GridView1.SelectedIndex).Cells(0).Text
        Response.Redirect("Details Page.aspx?id=" + str)
    End Sub
End Class
